package com.breeze.components.mybatis.base;

import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import com.mybatisflex.annotation.Column;
import com.mybatisflex.annotation.Id;
import com.mybatisflex.annotation.KeyType;
import com.mybatisflex.core.activerecord.Model;
import io.swagger.v3.oas.annotations.media.Schema;
import java.io.Serial;
import java.io.Serializable;
import java.time.LocalDateTime;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * @author breeze
 */
@Data
@EqualsAndHashCode(callSuper = true)
public abstract class BaseModel<T extends Model<T>> extends Model<T> implements Serializable {

  @Serial private static final long serialVersionUID = 1L;

  @Schema(title = "唯一id", type = "string")
  @JsonSerialize(using = ToStringSerializer.class)
  @Id(keyType = KeyType.Generator, value = "snowIdGenerator")
  private Long id;

  @Schema(description = "创建时间")
  @Column(onInsertValue = "now()")
  private LocalDateTime createTime;

  @Schema(description = "更新时间")
  @Column(onUpdateValue = "now()")
  private LocalDateTime updateTime;

  @Schema(description = "创建人")
  private Long createBy;

  @Schema(description = "更新人")
  private Long updateBy;

  @Schema(description = "版本号", nullable = true)
  @Column(version = true)
  private Integer version;

  @Schema(title = "是否删除")
  @Column(isLogicDelete = true)
  private Integer deleteFlag;
}
